package admin

import (
	database "hft/Database"
)

type Account struct {
	database.Base
	PID      uint   `json:"-" gorm:"foreignKey:PID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:NO ACTION"`
	Username string `json:"username,omitempty" gorm:"type:varchar(30);size:30;uniqueIndex"`
	Password string `json:"password,omitempty"`
	// NickName       string         `json:"nickname,omitempty"`
	RoleName       string         `json:"roleName,omitempty"`
	IsAudit        int            `json:"isAudit" gorm:"type:tinyint(1);size:1;default:0"`
	Avatar         string         `json:"avatar,omitempty" gorm:"type:text"`
	IDCard         string         `json:"idCard" gorm:"type:varchar(255);size:255"`
	Status         bool           `json:"status,omitempty" gorm:"column:status;type:tinyint(1);default:1"`
	Phone          string         `json:"phone,omitempty" gorm:"uniqueIndex"`
	RoleId         uint           `json:"roleId,omitempty"`
	Role           *Role          `json:"role" gorm:"foreignKey:RoleId;references:ID;constraint:OnDelete:NO ACTION,OnUpdate:NO ACTION"`
	Belong         uint           `json:"belong,omitempty"`
	RegionType     string         `json:"regionType,omitempty"`
	RealName       string         `json:"realName"`
	Link           string         `json:"-" gorm:"type:varchar(255);size:255;index"`
	LouPan         []*LouPan      `json:"louPan" gorm:"many2many:_account_lou_pan;foreignKey:ID;references:ID;constraint:OnDelete:CASCADE;OnUpdate:NO ACTION"`
	AccountExpand  AccountExpand  `json:"accountExpand" gorm:"foreignKey:AccountId;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`
	IsSetRegion    bool           `json:"is_set_region,omitempty" gorm:"column:is_set_region;type:tinyint(1);default:0;not null;comment:是否设置了地区"`
	RegionLink     string         `json:"region_link,omitempty" gorm:"type:text"`
	AccountLink    string         `json:"-" gorm:"column:account_link;type:varchar(255);size:255;index"`
	IsChildAccount bool           `json:"canBeSetRegion" gorm:"-"`
	CanBeSetRegion bool           `json:"roleCanSetRegion"`
	OpenId         string         `json:"openId" gorm:"index"` //用户微信的id
	Qrcode         string         `json:"qrcode"`              //用户临时二维码
	Company        string         `json:"company" gorm:"default:'';comment:公司名字"`
	Regions        []*Region      `json:"regions,omitempty" gorm:"foreignKey:ManageId;references:ID;constraint:OnDelete:NO ACTION,OnUpdate:SET NULL"`
	Accounts       []*Account     `json:"children,omitempty" gorm:"foreignKey:PID"`
	ArticleTypes   []*ArticleType `gorm:"foreignKey:AccountId;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`
}

func (Account) TableName() string {
	return database.TableNameFormat("accounts")
}
